<template>
  <div class="app-container">
    <ContractNewAdd  ref="openContractNewAdd" @refresh="refresh"></ContractNewAdd>
    <ContractVersion  ref="openContractVersion" @refresh="refresh"></ContractVersion>
    <ConstractNewVersionAdd  ref="openConstractNewVersionAdd" @refresh="refresh"></ConstractNewVersionAdd>
    <el-form @submit.native.prevent :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="60px" :label-position="labelPosition">
      <el-form-item label="客户" prop="khmc">
        <el-input
          v-model="queryParams.khmc"
          placeholder="请输入客户"
          :disabled="true"
        />
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="contractFeeStandardDetail"
    >
      <af-table-column fixed="left" width="230" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="contractDetail(scope.row)"
            v-hasPermi="['zhcloud:sfbz:detail']"
          >合同详细</el-button>
             <el-button
            size="mini"
            type="text"
            @click="contractVersion(scope.row)"
            v-hasPermi="['zhcloud:sfbz:list']"
          >合同版次</el-button>
             <el-button
            size="mini"
            type="text"
            @click="contractNewVersionAdd(scope.row)"
            v-hasPermi="['zhcloud:sfbz:list']"
          >添加新版次</el-button>
        </template>
      </af-table-column> 
      <af-table-column prop="csbh" label="合同编号" width="180" fixed="left"></af-table-column>
      <af-table-column prop="cx" label="当前版次"></af-table-column>
      <af-table-column prop="sm" label="合同开始日期"></af-table-column>
      <af-table-column prop="em" label="合同结束日期"></af-table-column>
      <af-table-column prop="itbz" label="备注"></af-table-column>
      <af-table-column prop="rsopmc" label="创建人"></af-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="pageNum"
      :limit.sync="pageSize"
      @pagination="getList"
    />
    <el-row :gutter="10" class="mt20" type="flex" justify="center">
      <el-col :span="1.5">
        <el-button type="primary" @click="handleAddNewContract" v-hasPermi="['zhcloud:sfbz:add']">添加新合同</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button @click="goContractFeeStandard">返回</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getContractDetail } from "@/api/storage/contractFeeStandard";
import ContractNewAdd from './contractNewAdd.vue'
import ContractVersion from './contractVersion.vue'
import ConstractNewVersionAdd from './constractNewVersionAdd.vue'

export default {
  name: "ContractDetail",
  components:{ ContractNewAdd,ContractVersion, ConstractNewVersionAdd },
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //表格加载
      loading:true,
       //对齐
      labelPosition: "right",
      //客户加载
      selectClient3Loading:true,
      // 查询参数
      queryParams: {
        khid: "",
        khmc:""
      },
      // 费用总览列表
      contractFeeStandardDetail: [],
      //页数
      pageSize: 999,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  beforeRouteEnter(to, from, next) {
    const query = to.query
    next(vm => {   
      if(Object.keys(query).length > 0) {
        vm.queryParams = {
          khmc:query.khmc,
          khid:query.khid
        }
        vm.getList()
      }
    })
  },
  methods: {
    /** 查询费用总览 */
    getList() {
      this.loading = true
      getContractDetail(this.queryParams, {pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        this.contractFeeStandardDetail = response.data;
        this.loading = false
      });
    },
    /**添加新合同 */
    handleAddNewContract() {
      this.$refs.openContractNewAdd.open(this.queryParams)
    },
    //打开合同详情
    contractDetail(row) {
      const query = this.$route.query
      row.khmc = query.khmc
      const data = JSON.parse(JSON.stringify(row))
      this.$router.push({path:"/storage/contractFeeStandard/contractDetailList", query:data})
    },
    //打开合同版次 
    contractVersion(row) {
      const data = JSON.parse(JSON.stringify(row))
      this.$refs.openContractVersion.open(data)
    },
    //打开新版本
    contractNewVersionAdd(row) {
      const data = JSON.parse(JSON.stringify(row))
       this.$refs.openConstractNewVersionAdd.open(data)
    },

    /**返回不刷新 */
    goContractFeeStandard() {
      this.$router.push({name:"ContractFeeStandard"})
    },

    refresh() {
      this.getList()
    },

    /**enter键触发 */
    enterClick(e) {
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.reset()
      this.getList()
    },
    reset() {
      Object.assign(this.$data, this.$options.data())
    },
  }
};
</script>
